from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.
from signup.models import Student


def signup(request):

    return render(request, 'index.html')


def qrcode(request):
    name = request.GET.get('name')
    uid = request.GET.get('uid')
    context = {
        'name': name,
        'uid': uid,
        'url': f'http://127.0.0.1:8000/check/?name={name}&uid={uid}'
    }
    return render(request, 'qr_code.html', context)


def check(request):
    name = qrcode(request).name
    uid = qrcode(request).uid
    students = Student.objects.create(name=name, uid=uid)
    students.save()
    message = f'{name}{uid}签到成功！'
    return HttpResponse(message)
